package com.bupt.utils;

import com.bupt.exception.BaseException;

import java.util.HashMap;
import java.util.Map;

// 网络的层次信息
enum LayerEnum {
    FIBER("FIBER"), WDM("WDM"), SDH("SDH"), OTN("OTN"),SATELLITE("SATELLITE"), SHORTWAVE("SHORTWAVE");
    private final String layer;
    private static final Map<String, LayerEnum> map = new HashMap<>();

    static {
        for (LayerEnum layer : values()) { // values() 这个方法是 Java 编译后自动产生的
            if (null != map.put(layer.layer, layer)) {
                throw new IllegalArgumentException("存在严重问题 layer 一样 启动失败");
            }
        }
    }

    LayerEnum(String layer) {
        this.layer = layer;
    }

    public static LayerEnum getLayerEnum(String layer) throws BaseException {
        LayerEnum layerEnum = map.get(layer);
        if (null != layerEnum) return layerEnum;
        throw new BaseException("layer 应当为 FIBER、WDM、SDH、OTN");
    }

    public String getLayer() {
        return layer;
    }
}
